/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fiu.accesslog.statistics;

import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Hasan Mahmud @date Jun 10, 2012
 */
public class RecordUtility
{

        public static ArrayList<Info> getClonedArrayList(HashMap<String, Info> hMap)
        {
                ArrayList<Info> originalList = new ArrayList<Info>(hMap.values());
                ArrayList<Info> clonedList = new ArrayList<Info>(originalList.size());
                for (Info item : originalList)
                {
                        clonedList.add(item.clone());
                }

                return clonedList;
        }

        public static void trimArrayList(ArrayList<Info> sortedList, String title, int maxRecord)
        {
                Info otherInfo = new Info(title, 0), temp;
                for (int i = maxRecord - 1; i < sortedList.size();)
                {
                        temp = sortedList.remove(i);
                        otherInfo.totalHit += temp.totalHit;
                }
                sortedList.add(otherInfo);
                //System.out.println(sortedList.size());
        }

        public static void addInHashMap(HashMap hMap, String key, boolean isUnique)
        {
                if (hMap.containsKey(key))
                {
                        Info cInfo = (Info) hMap.get(key);
                        cInfo.totalHit++;
                        if (isUnique)
                        {
                                cInfo.uniqueHit++;
                        }
                }
                else
                {
                        hMap.put(key, new Info(key, 1, isUnique ? 1 : 0));
                }


        }

        public static void printArray(ArrayList<Info> array, String title, int maxRecord)
        {
                Info temp;
                System.out.println(title);
                int i = 0;
                for (; i < maxRecord  && i < array.size() ; i++)
                {
                        temp = array.get(i);
                        System.out.println("Key: " + temp.keyName + "     Total Hit: " + temp.totalHit + "     Unique Hit: " + temp.uniqueHit);
                }
                System.out.println("Total Record Printed: "+i);
        }
}
